package com.lm.scau.framedemos.Dagger2;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.lm.scau.framedemos.BaseActivity;
import com.lm.scau.framedemos.R;
import com.lm.scau.framedemos.Views.LMTitleBar;
import com.lm.scau.framedemos.Views.SunmaryView;

import javax.inject.Inject;

/**
 * Function:
 * auth：liming on 2016/6/30 10:06
 * mail：liming@wxchina.com
 */
public class DaggerActivity extends BaseActivity {
    private SunmaryView sunmaryView;

    @Inject
    Printer printer;

    private TextView areaTitle1;
    private TextView areaTitle2;
    private TextView areaInfo1;
    private TextView areaInfo2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger2);
      //  DaggerAComponent.builder().build().inject(this);
        initView();
        initAction();
    }

    private void initAction() {
        sunmaryView.getBtnCancel().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                areaTitle1.setText("");
                areaTitle2.setText("");
                areaInfo1.setText("");
                areaInfo2.setText("");
            }
        });
        sunmaryView.getBtnOk().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                printer.print("user");
            }
        });
    }

    private void initView() {
        mTitleBar = (LMTitleBar) findViewById(R.id.titlebar);
        sunmaryView = (SunmaryView)findViewById(R.id.sunmary_view);

        areaTitle1 = (TextView)findViewById(R.id.tv_area_title1) ;
        areaTitle2 = (TextView)findViewById(R.id.tv_area_title2) ;
        areaInfo1 = (TextView)findViewById(R.id.tv_area_info1) ;
        areaInfo2 = (TextView)findViewById(R.id.tv_area_info2) ;

        mTitleBar.setTitle("Dagger2");
        sunmaryView.setTitle("Dagger2");
        sunmaryView.setSunmary("依赖注入（Dependency Injection），简称DI，又叫控制反转（Inversion of Control），简称IOC。" +
                "当一个类的实例需要另另一个类的实例进行协助时，在传统的设计中，通常由调用者来创建被调用者的实例，然而依赖注入的方式，创建被调用者不再由调用者创建实例，创建被调用者的实例的工作由IOC容器来完成，然后注入到调用者。因此也被称为依赖注入。");
    }
}
